import sys, os, string

platform = sys.platform

##try:
##    geckosdk = os.environ['GECKO_SDK']
##    if geckosdk[-1] != os.sep: geckosdk += os.sep
##except:
##    print "Please set environment variable GECKO_SDK first."
##    sys.exit(1)
xulrunner_sdk = '/home/guohuan/tmp/xulrunner/1.9b3/xulrunner-sdk/'
geckosdk = xulrunner_sdk + 'sdk/'
xpidl = geckosdk + 'bin/xpidl' 
gecko_idl = geckosdk + 'idl'
# Create two builders to create xpt and header files from idl.
bxpt = Builder(action = xpidl + ' -w -m typelib -Icomponents -I' + gecko_idl + ' -e $TARGET $SOURCE', suffix = '.xpt', src_suffix = '.idl')
bhdr = Builder(action = xpidl + '  -w -m header -Icomponents -I' + gecko_idl + ' -e $TARGET $SOURCE', suffix = '.h',   src_suffix = '.idl')

# Create environment object for build
env = Environment(
    CPPPATH = [geckosdk + 'include', xulrunner_sdk + 'include' , xulrunner_sdk + 'include/xpcom'],
    LIBPATH = [geckosdk + 'lib' , ],
    LIBS = ['xpcomglue', 'nspr4', 'plds4' , 'xpcomglue_s.a','xul'],
    ENV = os.environ)
env.AppendENVPath('PATH', geckosdk + 'bin')
env.Append(BUILDERS = {'MozXPT' : bxpt, 'MozHeader' : bhdr})

# Add additional param for different platforms
if platform == 'linux2':
    env.AppendUnique(
        CXXFLAGS = ['-include', 'xpcom-config.h',
                    '-Wall', '-O2',
                    '-fno-rtti', '-fno-exceptions',
                    '-Wconversion',
                    '-Wpointer-arith', '-Wcast-align',
                    '-Woverloaded-virtual',
                    '-Wsynth', '-fshort-wchar',
                    '-Wno-ctor-dtor-privacy',
                    '-Wno-non-virtual-dtor',
                    '-Wno-long-long',
                    '-pedantic',
                    '-fshort-wchar',
                    '-pthread', '-pipe'])

# Create headers and xpt files from idl
xpts = [env.MozXPT('IFetionCom')]
headers = [env.MozHeader('IFetionCom')]

parts = []
if platform == 'linux2':
    parts.extend(['fetionCom.cpp', 'fetionComModule.cpp','md5.cpp' , 'regFetion.cpp'])

antleripc = env.SharedLibrary('fetionCom', parts)

Default([xpts, headers, antleripc])
